// API 相关类型定义

export interface ChatRequest {
  sessionId?: string
  question: string
  includeDetails?: boolean
}

export interface DatabaseOperationResult {
  success: boolean
  operation: string
  executedSql: string
  data?: Array<Record<string, any>>
  affectedRows: number
  errorMessage?: string
  executionTimeMs: number
  totalCount?: number
  metadata?: Record<string, any>
}

export interface IntentResult {
  operation: 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE' | 'COUNT' | 'UNKNOWN'
  tableName: string
  fields?: string[]
  conditions?: Array<{
    field: string
    operator: string
    value: any
    logical?: 'AND' | 'OR'
  }>
  updateData?: Record<string, any>
  insertData?: Record<string, any>
  orderBy?: Array<{
    field: string
    direction: 'ASC' | 'DESC'
  }>
  limit?: number
  offset?: number
  groupBy?: string[]
  aggregations?: Array<{
    type: 'COUNT' | 'SUM' | 'AVG' | 'MAX' | 'MIN'
    field: string
    alias?: string
  }>
  originalQuestion: string
  confidence: number
}

export interface ChatResponse {
  success: boolean
  message: string
  databaseResult?: DatabaseOperationResult
  intentResult?: IntentResult
  errorMessage?: string
  sessionId: string
  timestamp: number
  totalExecutionTime: number
}

export interface ChatLog {
  id: number
  sessionId: string
  userQuestion: string
  aiIntent?: string
  generatedSql?: string
  sqlResult?: string
  aiResponse?: string
  executionStatus: 'SUCCESS' | 'FAILED' | 'PARTIAL_SUCCESS'
  errorMessage?: string
  executionTimeMs?: number
  createdAt: string
}

export interface ChatStatistics {
  totalCount: number
  successCount: number
  failedCount: number
  partialSuccessCount: number
  averageExecutionTimeMs: number
}

export interface SystemHealth {
  status: 'UP' | 'DOWN'
  timestamp: number
  components: {
    database: {
      status: 'UP' | 'DOWN'
      description: string
    }
    ai_service: {
      status: 'UP' | 'DOWN'
      description: string
    }
  }
}

export interface SystemInfo {
  application: string
  version: string
  description: string
  java_version: string
  spring_boot_version: string
  startup_time: number
  memory: {
    max: number
    total: number
    free: number
    used: number
  }
}

// 组件相关类型
export interface MessageItem {
  id: string
  type: 'user' | 'assistant' | 'system'
  content: string
  timestamp: number
  data?: any
  loading?: boolean
  error?: boolean
}